// disconnected new entity
var student = new Student(){ StudentName = "Bill" };
using (var context = new SchoolDBEntities())
{
context.Entry(student).State = student.StudentId == 0? EntityState.Added : EntityState.Modified;
context.SaveChanges();
}
// disconnected existing entity
var student = new Student(){ StudentId = 1, StudentName = "Steve" };
using (var context = new SchoolDBEntities())
{
context.Entry(student).State = student.StudentId == 0? EntityState.Added : EntityState.Modified;
context.SaveChanges();
}
exec sp_executesql N'INSERT [dbo].[Student]([StudentName], [StandardId])
VALUES (@0, NULL)
SELECT [StudentID] FROM [dbo].[Student]
WHERE @@ROWCOUNT > 0 AND [StudentID] = scope_identity(),@0='Bill'